Tuples

  • Tuples have a fixed  length: once declared, they cannot grow or shrink in size.

  • The types of the different values in the tuple don’t have to be the same.

Creation

let tup: (i32, f64, u8) = (500, 6.4, 1);

Access

  • Via Index:

    let x: (i32, f64, u8) = (500, 6.4, 1);
    
    let five_hundred = x.0;
    
    let six_point_four = x.1;
    
    let one = x.2;
    
  • Via Destructuring:

    let tup = (500, 6.4, 1);
    
    let (x, y, z) = tup;
    
    println!("The value of y is: {y}");